RTP GB28181 udp 转发桥 您所在的位置:网站首页 websocket rtp RTP GB28181 udp 转发桥

RTP GB28181 udp 转发桥

#RTP GB28181 udp 转发桥| 来源: 网络整理| 查看: 265

目的

通往外网只有一个节点可以通,这个时候我们需要一个转发桥, 做一个udp 转发桥是非常简单的,简单而有用,我们使用asio c++ 来编程序

原理

使用asio 异步接收并且发送,在接收到以后,立刻在桥上转发,转发到外网地址。这里做演示,程序里面使用的是127.0.0.1.

代码 #define ASIO_STANDALONE #include #include #include #include "asio.hpp" using asio::ip::udp; static const asio::ip::udp::endpoint s_end_point(asio::ip::address::from_string("127.0.0.1"), 6000); class TicToc { public: TicToc() { tic(); } void tic() { start = std::chrono::system_clock::now(); } double toc() { end = std::chrono::system_clock::now(); std::chrono::duration elapsed_seconds = end - start; start = end; return elapsed_seconds.count() ; } private: std::chrono::time_point start, end; }; class server { private: TicToc v_tock; public: server(asio::io_context& io_context, short port) : socket_(io_context, udp::endpoint(udp::v4(), port)) { do_receive(); } int64_t v_i = 0; uint64_t v_recvbytes = 0; void do_receive() { socket_.async_receive_from( asio::buffer(data_, max_length), sender_endpoint_, [this](std::error_code ec, std::size_t bytes_recvd) { if (!ec && bytes_recvd > 0) { if (v_i == 0) v_tock.tic(); v_recvbytes += bytes_recvd; if (v_i++ > 100) //每一百个包统计一次 { double res = v_tock.toc(); float m = v_recvbytes / res /1000.0f; std::cout socket_.async_send_to( asio::buffer(data_, length), s_end_point, [this](std::error_code /*ec*/, std::size_t /*bytes_sent*/) { do_receive(); }); } private: udp::socket socket_; udp::endpoint sender_endpoint_; udp::endpoint sender_to; enum { max_length = 1500 }; char data_[max_length]; }; int main(int argc, char* argv[]) { try { /*if (argc != 2) { std::cerr


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有